$(document).ready(function(){
    var interval = 0;
    var ids;

        $('#prev').click(function(){
            interval--;
            //alert(interval);            
            jQuery('#next').attr("disabled",false); 
            jQuery('#list').jqGrid('setGridParam',{url:'./ajax/mpartystock.php?q=1&id='+ids+'&inv='+interval,page:1}); 
            jQuery('#list').jqGrid('setCaption','Party Stock List:').trigger('reloadGrid'); 
        });

        $('#next').click(function(){
            if(interval < 1){
                interval++;
                if(interval == 1)
                    jQuery('#next').attr("disabled",true); 
            }
            //else {
                //jQuery('#next').attr("disabled",true); 
            //}
            //alert(interval);            
            jQuery('#list').jqGrid('setGridParam',{url:'./ajax/mpartystock.php?q=1&id='+ids+'&inv='+interval,page:1}); 
            jQuery('#list').jqGrid('setCaption','Party Stock List:').trigger('reloadGrid'); 
        });

	$('#party').change(function(){

            ids =this.value;

            if(ids == null || ids <1) { 
                ids=0; 
                //if(jQuery('#list').jqGrid('getGridParam','records') >0 ) { 
                    jQuery('#list').jqGrid('setGridParam',{url:'./ajax/mpartystock.php?q=1&id='+ids+'&inv='+interval,page:1}); 
                    jQuery('#list').jqGrid('setCaption','Party Stock List:').trigger('reloadGrid');
                //} 
            } else { 
                jQuery('#list').jqGrid('setGridParam',{url:'./ajax/mpartystock.php?q=1&id='+ids+'&inv='+interval,page:1}); 
                jQuery('#list').jqGrid('setCaption','Party Stock List:').trigger('reloadGrid'); 
            } 

        });


        jQuery('#list').jqGrid({
            url:'./ajax/mpartystock.php?q=1&id=0&inv=0',
            datatype: 'xml',
            mtype: 'GET',
            colNames:['SN','Date', 'Product','N.D.Price','No. in Case','No. of Case','Amount'],
            colModel :[ 
            {name:'id', index:'id', width:25,sortable:false}, 
            {name:'collected_date', index:'collected_date', width:50, align:'left',sortable:false}, 
            {name:'product', index:'product', width:100, align:'left',sortable:false}, 
            {name:'ndprice', index:'ndprice', width:60, align:'left',sortable:false}, 
            {name:'noincase', index:'noincase', width:50, align:'left',sortable:false}, 
            {name:'noofcase', index:'noofcase', width:50, align:'left',sortable:false}, 
            {name:'amount', index:'amount', width:50, align:'right',sortable:false,formatter:'number'}, 
            ],
            pager: '#pager',
            rowNum:8,
                width:500,
                height:300,
                hidegrid:false,
            rowList:[10,20,30],
            sortname: 'collected_date',
            sortorder: 'DESC',
            viewrecords: true,
            imgpath: '',
            caption: 'Party Stock List',
        }); 

        $('#party').change();	
});
